﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Enterprice : System.Web.UI.Page
{
    private int type;
    private StringBuilder sb;
    private char[] unsafeChar = new char[] { ',', ';', '\'' };
    protected void Page_Load(object sender, EventArgs e)
    {
        sb=new StringBuilder();
        

        try
        {
          type=int.Parse(Request["type"]);
        }
        catch (Exception ex)
        {
            sb.AppendFormat("<typeError>类型参数格式不对:{0}</typeError>",ex.Message);
            sb.AppendFormat("<register>注册参数为:{0}</register>",(int)EnterpriceType.Register);
            sb.AppendFormat("<login>登陆参数为:{0}</login>", (int)EnterpriceType.Login);
            outputXML();
        }


        string name=string.Empty;
        string pwd=string.Empty;
        bool hasError = false;

        if (string.IsNullOrEmpty(Request["userName"]))
        {
            sb.Append("<userNameError>用户名没有提供</userNameError>");
            hasError = true;
        }else{
            name=Request["userName"].Trim(unsafeChar);
        }
        if (string.IsNullOrEmpty(Request["passWord"]))
        {
            sb.Append("<passWordError>密码没有提供</passWordError>");
            hasError = true;
        }else{
            pwd=  Request["passWord"].Trim(unsafeChar);
        }

        if (hasError)
        {
            outputXML();
        }

        

        if(name.Length<3){
            sb.Append("<userNameError>用户名太短</userNameError>");
            hasError = true;
        }
        if (pwd.Trim().Length < 3)
        {
            sb.Append("<passWordError>密码太短</passWordError>");
            hasError = true;
        }
        if (hasError)
        {
            outputXML();
        }

        switch (type)
        {
            case (int)EnterpriceType.Register:
                Register(name, pwd);
                break;
            case (int)EnterpriceType.Login:
                Login(name, pwd);
                break;
            default:
                break;
        }
        outputXML();
    }

    /// <summary>
    /// 注册;
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="passWord"></param>
    public void Register(string userName, string passWord)
    {
        sb.AppendFormat("<loading>正在进行注册...</loading>");
    }

    /// <summary>
    /// 登陆;
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="passWord"></param>
    public void Login(string userName, string passWord)
    {
        sb.AppendFormat("<loading>正在进行登陆...</loading>");
    }



    /// <summary>
    /// 输出xml;
    /// </summary>
    public void outputXML()
    {
        Response.ContentType = "text/xml";
        Response.Clear();

        Response.Write(String.Format("<root>{0}</root>", sb.ToString()));
        Response.End();
    }
}


/// <summary>
/// 枚举企业传过来的行为;
/// </summary>
public enum EnterpriceType
{
    Register = 0,
    Login = 2

}
